/*
 * @Author: byron
 * @Date: 2021-10-23 09:30:17
 * @LastEditTime: 2022-02-16 21:18:01
 */
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'

module.exports = {
    publicPath: '/',
    outputDir: 'dist',
    devServer: {
        open: true, // 启动后自动打开浏览器
        port: 8090, // 端口
    },
    chainWebpack(config) {
        //修改htmlWebpackPlugin
        config.plugin('html').tap((args) => {
            args[0].title = '博客后台管理系统'
            return args
        })
    },
    configureWebpack: (config) => {
        if (isProduction) {
            config.mode = 'production'
            config['performance'] = {
                //打包文件大小配置
                maxEntrypointSize: 10000000,
                maxAssetSize: 30000000,
            }
            // 为生产环境修改配置...
            return {
                plugins: [
                    new UglifyJsPlugin({
                        uglifyOptions: {
                            //生产环境自动删除console
                            compress: {
                                drop_debugger: true,
                                drop_console: true,
                                pure_funcs: ['console.log'],
                            },
                        },
                        sourceMap: false,
                        parallel: true,
                    }),
                ],
            }
        }
    },
}
